/**
 * 动态插入css
 */
import iconList from './iconList'
// icon存放路径
const PRE_ICON_PATH = 'cdn/iconfont/normal'

window.YT_ICON_LIST = iconList
export const loadIconFont = () => {
  // require.context不能在循环中使用,因为require.context的参数只能使用字面值，不能使用变量代替
  let context = require.context('../normal', true, /\.css$/)
  context.keys().forEach(key => {
    const url = PRE_ICON_PATH + key.substr(1)
    loadStyle(url)
  })
}

export const loadStyle = url => {
  const link = document.createElement('link')
  link.type = 'text/css'
  link.rel = 'stylesheet'
  link.href = url
  const head = document.getElementsByTagName('head')[0]
  head.appendChild(link)
}

loadIconFont()
